package com.commonmodule.commonmodule.util;

import com.commonmodule.commonmodule.enums.AuthEnum;
import lombok.Data;

//import java.io.Serial;
//import java.io.Serial;
import java.io.Serializable;

/**
 * @author zxb
 * @version 1.0
 * @date 2024-10-24 11:07
 */
@Data
public class R<T> implements Serializable {


//    @Serial
    private static final long serialVersionUID = 1L;
    private Integer code;
    private String msg;
    private T data;

    private R(){

    }



    public static <T> R<T> ok(T data) {
        R<T> response = new R<>();
        response.setCode(AuthEnum.SUCCESS.getCode());
        response.setMsg(AuthEnum.SUCCESS.getMsg());
        response.setData(data);
        return response;
    }

    public static <T> R<T> ok() {
        R<T> response = new R<>();
        response.setCode(AuthEnum.SUCCESS.getCode());
        response.setMsg(AuthEnum.SUCCESS.getMsg());
        response.setData(null);
        return response;
    }


    public static <T> R<T> error(AuthEnum responseEnum){
        R<T> response = new R<>();
        response.setCode(responseEnum.getCode());
        response.setMsg(responseEnum.getMsg());
        return response;
    }

    public static <T> R<T> error(){
        R<T> response = new R<>();
        response.setCode(500);
        response.setMsg("请求超时");
        return response;
    }


    public static <T> R<T> error(Integer errorCode, String errorMsg){
        R<T> response = new R<>();
        response.setCode(errorCode);
        response.setMsg(errorMsg);
        return response;
    }










}
